//
//  MNDReturnListIndicator.m
//  minidai
//
//  Created by Steven.Yung on 2017/6/6.
//  Copyright © 2017年 迷你金服. All rights reserved.
//

#import "MNDReturnListIndicator.h"

@interface MNDReturnListIndicator ()

@property (strong, nonatomic) UIView *indicatorView;
@property (strong, nonatomic) UIButton *leftBtn;
@property (strong, nonatomic) UIButton *rightBtn;

@end

@implementation MNDReturnListIndicator

- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    
    if (self) {
        [self initialContents];
    }
    return self;
}

- (void)initialContents {
    
    self.leftBtn = [self buttonWithTitle:@"待回款"];
    self.leftBtn.tag = 100;
    [self.leftBtn setSelected:YES];
    
    self.rightBtn = [self buttonWithTitle:@"已回款"];
    self.rightBtn.tag = 101;
    
    self.segmentButtons = @[self.leftBtn, self.rightBtn];
    
    [self addSubview:self.leftBtn];
    [self addSubview:self.rightBtn];
    
    [self.leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.leading.equalTo(self);
        
    }];
    [self.rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.leftBtn);
        make.leading.equalTo(self.leftBtn.mas_trailing).offset(0);
        make.trailing.equalTo(self);
        make.width.equalTo(self.leftBtn);
    }];
    
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectZero];
    lineView.backgroundColor = [UIColor clearColor];
    [self addSubview:lineView];
    
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self);
        make.trailing.equalTo(self);
        make.height.mas_equalTo(1);
        make.bottom.equalTo(self);
    }];
    
    self.indicatorSpace = 0.0;
}

- (void)makIndicatorSpace {
    [self.indicatorView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.leftBtn).offset(self.indicatorSpace);
        make.bottom.equalTo(self);
        make.height.mas_equalTo(2);
        make.width.mas_equalTo(55);
        
    }];
}

- (void)setIndicatorSpace:(CGFloat)indicatorSpace {
    _indicatorSpace = indicatorSpace;
    
    [self makIndicatorSpace];
}


- (UIButton *)buttonWithTitle:(NSString *)title {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitle:title forState:UIControlStateSelected];
    [button setTitleColor:kColorBlack forState:UIControlStateNormal];
    [button setTitleColor:kColorOrange forState:UIControlStateSelected];
    
    button.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:18.0];
    
    return button;
}

- (UIView *)indicatorView {
    if (!_indicatorView) {
        _indicatorView = [[UIView alloc] initWithFrame:CGRectZero];
        _indicatorView.backgroundColor = kColorOrange;
        [self addSubview:_indicatorView];
        
    }
    
    return _indicatorView;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
